package com.corona.game;

import com.badlogic.gdx.graphics.Color;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.math.Matrix4;
import com.badlogic.gdx.math.Vector2;
import com.corona.Game;
import com.corona.game.action.DrawAction;
import com.corona.game.util.GameProfiler;
import java.util.Iterator;

/* compiled from: Player.java */
/* loaded from: pokewilds.jar:com/pkmngen/game/DrawBuildTile.class */
public class DrawBuildTile extends DrawAction {
    public Action.Layer layer = Action.Layer.map_108;
    public int terrainTimer = 0;
    Color prevColor = new Color();
    Matrix4 prevCombined = new Matrix4();

    public DrawBuildTile(GameProfiler profiler) {
        super(profiler);
    }

    @Override // com.corona.game.Action
    public String getCamera() {
        return "map";
    }

    @Override // com.corona.game.Action
    public Action.Layer getLayer() {
        return this.layer;
    }

    @Override // com.corona.game.action.DrawAction
    protected void draw(Game game) {
        if (Game.canUseFrameBuffers && game.player != null) {
            game.mapBatch.setProjectionMatrix(Game.identity);
            this.prevColor.set(game.mapBatch.getColor());
            game.mapBatch.setColor(1.0f, 1.0f, 1.0f, 1.0f);
            game.temp1 = game.mapBatch.getBlendSrcFunc();
            game.temp2 = game.mapBatch.getBlendDstFunc();
            game.mapBatch.setBlendFunction(774, 770);
            if (this.prevColor.r < 1.0f) {
                game.mapBatch.draw(game.frameBuffer.getColorBufferTexture(), -1.0f, 1.0f, 2.0f, -2.0f);
            }
            if (this.prevColor.r < 0.5f) {
                game.mapBatch.draw(game.frameBuffer.getColorBufferTexture(), -1.0f, 1.0f, 2.0f, -2.0f);
            }
            if (this.prevColor.r < 0.1f) {
                game.mapBatch.draw(game.frameBuffer.getColorBufferTexture(), -1.0f, 1.0f, 2.0f, -2.0f);
            }
            game.mapBatch.setBlendFunction(game.temp1, game.temp2);
            game.mapBatch.setColor(this.prevColor);
        }
        this.prevCombined.set(game.cam.combined);
        game.cam.update();
        game.mapBatch.setProjectionMatrix(game.cam.combined);
        if (game.player.currFieldMove.equals("BUILD")) {
            Vector2 pos = game.player.facingPos();
            Sprite sprite = new Sprite(game.player.currBuildTile.sprite);
            sprite.setAlpha(0.8f);
            sprite.setPosition(pos.x, pos.y);
            Tile nextTile = game.map.tiles.get(pos);
            boolean isTorch = nextTile != null && (game.player.currBuildTile.name.contains("torch") || game.player.currBuildTile.name.equals("house_clock1") || game.player.currBuildTile.name.contains("picture") || game.player.currBuildTile.name.contains("window"));
            if ((isTorch && !nextTile.isSolid) || (nextTile != null && nextTile.isSolid)) {
                sprite.setColor(1.0f, 0.7f, 0.7f, 0.8f);
            }
            boolean requirementsMet = true;
            Iterator<String> it = game.player.buildTileRequirements.get(game.player.currBuildTile.name).keySet().iterator();
            while (true) {
                if (!it.hasNext()) {
                    break;
                }
                String reqName = it.next();
                if (game.player.hasItem(reqName)) {
                    if (game.player.getItemAmount(reqName).intValue() < game.player.buildTileRequirements.get(game.player.currBuildTile.name).get(reqName).intValue()) {
                        requirementsMet = false;
                        break;
                    }
                } else {
                    requirementsMet = false;
                    break;
                }
            }
            if (nextTile != null && game.player.currBuildTile.name.contains("house")) {
                Tile upTile = game.map.interiorTiles.get(game.map.interiorTilesIndex).get(nextTile.position.cpy().add(0.0f, 16.0f));
                requirementsMet = requirementsMet && (upTile == null || upTile.name.contains("house") || upTile.name.contains("rug"));
            }
            if (isTorch) {
                requirementsMet = requirementsMet && !nextTile.items().containsKey("torch") && nextTile.isSolid && !nextTile.nameUpper.contains("roof");
                String[] notAllowedTiles = {"regi", "tree", "bush", "table", "bed", "shelf", "plant", "couch"};
                for (String name : notAllowedTiles) {
                    requirementsMet = requirementsMet && !nextTile.name.contains(name) && !nextTile.nameUpper.contains(name);
                }
            }
            if (nextTile != null && game.player.currBuildTile.name.contains("door")) {
                requirementsMet &= !game.map.overworldTiles.get(pos.cpy().add(0.0f, -16.0f)).nameUpper.contains("roof");
            }
            if (game.player.currBuildTile.name.contains("bridge")) {
                requirementsMet = requirementsMet && nextTile != null && nextTile.name.contains("water") && !nextTile.name.contains("bridge");
            }
            if (!requirementsMet) {
                sprite.setColor(1.0f, 0.7f, 0.7f, 0.8f);
            }
            sprite.draw(game.mapBatch);
            if (game.player.currBuildTile.overSprite != null) {
                Sprite sprite2 = new Sprite(game.player.currBuildTile.overSprite);
                sprite2.setAlpha(0.8f);
                sprite2.setPosition(pos.x, pos.y);
                if (nextTile != null && (nextTile.isSolid || nextTile.nameUpper.contains("door"))) {
                    sprite2.setColor(1.0f, 0.7f, 0.7f, 0.8f);
                }
                sprite2.draw(game.mapBatch);
            }
        } else if (game.player.currFieldMove.equals("DIG")) {
            Vector2 pos2 = game.player.facingPos();
            Tile nextTile2 = game.map.tiles.get(pos2);
            if (nextTile2 != null) {
                if (!nextTile2.nameUpper.contains("hole") && !nextTile2.name.contains("water5") && !nextTile2.name.contains("water2") && !nextTile2.name.contains("lava")) {
                    this.terrainTimer = 0;
                    game.player.currBuildTile = game.player.currDigTile;
                } else if (this.terrainTimer < 25) {
                    this.terrainTimer++;
                } else {
                    game.player.currBuildTile = game.player.buildTiles.get(game.player.buildTileIndex);
                }
            }
            Sprite sprite3 = new Sprite(game.player.currBuildTile.sprite);
            sprite3.setAlpha(0.8f);
            sprite3.setPosition(pos2.x, pos2.y);
            sprite3.draw(game.mapBatch);
        }
        if (game.player.currPlanting != null) {
            Vector2 pos3 = game.player.facingPos();
            Player.sproutSprite.setAlpha(0.7f);
            Player.sproutSprite.setPosition(pos3.x, pos3.y + 2.0f);
            Player.sproutSprite2.setPosition(pos3.x, pos3.y);
            Tile nextTile3 = game.map.tiles.get(pos3);
            if (game.player.currPlanting.contains("apricorn")) {
                if (nextTile3 != null && (!(nextTile3.name.equals("green1") || nextTile3.name.contains("flower") || nextTile3.name.contains("sand") || nextTile3.name.contains("snow") || nextTile3.name.contains("desert")) || nextTile3.nameUpper.contains("tree") || nextTile3.isSolid)) {
                    Player.sproutSprite.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                    Player.sproutSprite2.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                } else if (nextTile3 != null) {
                    Player.sproutSprite2.setColor(0.7f, 1.0f, 0.7f, 0.7f);
                }
            } else if (game.player.currPlanting.equals("manure")) {
                if (nextTile3 != null && !nextTile3.nameUpper.contains("fertilized") && (nextTile3.nameUpper.contains("tree_planted") || nextTile3.nameUpper.contains("bush2_color"))) {
                    Player.sproutSprite2.setColor(0.7f, 1.0f, 0.7f, 0.7f);
                } else if (nextTile3 != null) {
                    Player.sproutSprite2.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                }
            } else if (game.player.currPlanting.equals("miracle seed")) {
                if (nextTile3 != null && nextTile3.nameUpper.equals("") && (nextTile3.name.equals("green1") || nextTile3.name.contains("snow") || nextTile3.name.contains("sand") || nextTile3.name.contains("desert") || nextTile3.name.contains("green9") || nextTile3.name.contains("green10") || nextTile3.name.contains("green11") || nextTile3.name.contains("green12") || nextTile3.name.contains("green_savanna") || nextTile3.name.contains("flower"))) {
                    Player.sproutSprite2.setColor(0.7f, 1.0f, 0.7f, 0.7f);
                } else if (nextTile3 != null) {
                    Player.sproutSprite2.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                }
            } else if (game.player.currPlanting.equals("berry seed")) {
                if (nextTile3 != null && nextTile3.nameUpper.equals("") && (nextTile3.name.equals("green1") || nextTile3.name.contains("snow") || nextTile3.name.contains("sand") || nextTile3.name.contains("desert") || nextTile3.name.contains("green9") || nextTile3.name.contains("green10") || nextTile3.name.contains("green11") || nextTile3.name.contains("green12") || nextTile3.name.contains("volcano") || nextTile3.name.contains("savanna") || nextTile3.name.contains("graveyard") || nextTile3.name.contains("flower"))) {
                    Player.sproutSprite2.setColor(0.7f, 1.0f, 0.7f, 0.7f);
                } else if (nextTile3 != null) {
                    Player.sproutSprite2.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                }
            } else if (game.player.currPlanting.contains("rod")) {
                if (nextTile3 != null && nextTile3.name.contains("water")) {
                    Player.sproutSprite2.setColor(0.7f, 1.0f, 0.7f, 0.7f);
                } else if (nextTile3 != null) {
                    Player.sproutSprite2.setColor(1.0f, 0.7f, 0.7f, 0.7f);
                }
            }
            if (Player.drawSproutSprite) {
                Player.sproutSprite2.draw(game.mapBatch);
                if (game.player.currPlanting.contains("apricorn")) {
                    Player.sproutSprite.draw(game.mapBatch);
                }
            }
        }
        game.mapBatch.setProjectionMatrix(this.prevCombined);
    }
}
